import { Component, OnInit, Input } from '@angular/core';
import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms';
import { ElevatorRescueBean } from '../bean/elevatorRescue.bean';
import { Config } from '../../../../service/config';
import { NzModalService, NzModalSubject } from 'ng-zorro-antd';
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
import { HttpServcie } from '../../../../service/http.service';
import { NzNotificationService } from 'ng-zorro-antd';
import * as moment from 'moment';
@Component({
  selector: 'rescue-detail',
  templateUrl: './rescue-detail.component.html',
  styleUrls: ['./rescue-detail.component.scss']
})

export class RescueDetailComponent implements OnInit {
  elevatorRescueBean: ElevatorRescueBean = new ElevatorRescueBean();
  isDisable: boolean = true;
  picList = [];
  config = Config;
  isSpinning: boolean = true;
  constructor(
    private fb: FormBuilder,
    private modalService: NzModalService,
    private router: Router,
    private route: ActivatedRoute,
    private httpServcie: HttpServcie,
    private _notification: NzNotificationService,
    private currentModal: NzModalSubject
  ) { }

  ngOnInit() {
    this.route.paramMap.subscribe(data => {
      //查询电梯的信息
      this.httpServcie.emergencyRescueById(data.get("id")).subscribe(data => {
        if (data.data) {
          this.elevatorRescueBean = data.data;
          this.elevatorRescueBean.receivedTime = this.transformTime(this.elevatorRescueBean.receivedTime);
          this.elevatorRescueBean.arrivedTime = this.transformTime(this.elevatorRescueBean.arrivedTime);
          this.elevatorRescueBean.rescueEndTime = this.transformTime(this.elevatorRescueBean.rescueEndTime);
          this.elevatorRescueBean.suredTime = this.transformTime(this.elevatorRescueBean.suredTime);
          if (this.elevatorRescueBean.noCasualties == '1') {
            this.elevatorRescueBean.noCasualties = '有';
          } else if (this.elevatorRescueBean.noCasualties == '0') {
            this.elevatorRescueBean.noCasualties = '无';
          } else {
            this.elevatorRescueBean.noCasualties = '无记录';
          }

          this.elevatorRescueBean.protective = this.elevatorRescueBean.protective.replace(/1/, '层门封堵').replace(/2/, '封闭通道').replace(/3/, '设置警戒线').replace(/4/, '封闭现场').replace(/5/, '其它措施').replace(/6/, '检查后符合安全要求，继续投入使用');


        }

      })
    });
  }

  //返回
  toBack() {
    window.history.back();
  }

  transformTime(value) {
    if (!value) {
      return null;
    }
    let values = value + '';
    let date = values.substring(0, 8);
    let time = values.substring(8, 14);
    let dates = moment(date).format('YYYY-MM-DD');
    let times = time.substring(0, 2) + ':' + time.substring(2, 4) + ':' + time.substring(4, 6);

    return dates + ' ' + times;
  }

  showLargeImage(titlepic, contentpic, footerpic, img) {

    this.picList = [];
    this.picList.push(img);
    this.currentModal = this.modalService.open({
      title: titlepic,
      content: contentpic,
      footer: footerpic,
      maskClosable: false,
      width: 800,
      style: {
        top: '20px'
      },
      onOk() {
        console.log('Click ok');
      }
    });
  }

}
